package com.aaa.outbound.service.impl;


import com.aaa.entity.outbound.Pick;
import com.aaa.entity.outbound.Picktask;
import com.aaa.entity.outbound.ViewPicktask;
import com.aaa.outbound.mapper.PicktaskMapper;
import com.aaa.outbound.service.PicktaskService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author wjf
 * @since 2020-11-26
 */
@Service
public class PicktaskServiceImpl extends ServiceImpl<PicktaskMapper, Picktask> implements PicktaskService {
    @Autowired
    private PicktaskMapper picktaskMapper;

    @Override
    public Page<Picktask> searchPicktask(Integer page, Integer limit, Picktask picktask) {
        Page<Picktask> pageinfo=new Page<>(page,limit);
        String picktaskno=picktask.getPicktaskno();
        String receiver=picktask.getReceiver();
        QueryWrapper<Picktask> queryWrapper=new QueryWrapper<>();
        if(StringUtils.isNotEmpty(picktaskno)){
            queryWrapper.like("picktaskno",picktaskno);
        }
        if(StringUtils.isNotEmpty(receiver)){
            queryWrapper.like("receiver",receiver);
        }
        this.picktaskMapper.selectPage(pageinfo,queryWrapper);
        return pageinfo;
    }

    @Override
    public Integer addPicktask(Picktask picktask) {
        Date now = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
        picktask.setId(null);
        picktask.setPicktaskno("PI"+dateFormat.format(now));
        return picktaskMapper.insert(picktask);
    }

    @Override
    public List<Picktask> selectPicktasknoByPicktask() {
        return picktaskMapper.selectPicktasknoByPicktask();
    }

    @Override
    public List<ViewPicktask> selectViewPicktaskByPicktaskno(String picktaskno) {
        return picktaskMapper.selectViewPicktaskByPicktaskno(picktaskno);
    }
}
